package com.yanqu.road.dataHelper.action;

import com.yanqu.road.dataHelper.action.excel.TrystAc;
import com.yanqu.road.dataHelper.gameServer.GameServer;
import com.yanqu.road.dataHelper.manager.DataMgr;
import com.yanqu.road.dataHelper.manager.ServerMgr;
import com.yanqu.road.entity.servercenter.ServerInfo;
import com.yanqu.road.utils.string.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;


//幽会活动
public class TrystAcExcel extends actionBase{
    public void go(List<Long> serverList){
        ExecutorService executorService = Executors.newFixedThreadPool(5);
        List<Future> futureList = new ArrayList<>();

        String activityIdStr = "9004604";
//        activityIdStr = "9883322";
        List<Integer> activityIdList = StringUtils.stringToIntegerList(activityIdStr,",");
       /* for(int activityId : activityIdList){
            futureList = new ArrayList<>();
            for(Long serverId : serverList){
                if(ServerMgr.getServerInfoList().containsKey(serverId)){
                    ServerInfo serverInfo = ServerMgr.getServerInfoList().get(serverId);
                    Future future = executorService.submit(new Callable<Boolean>() {
                        @Override
                        public Boolean call() throws Exception {
                            GameServer testGameServer = new GameServer(serverInfo);
                            TrystAc touhu = new TrystAc(testGameServer);
                            touhu.goAllActivity(activityId);
                            return true;
                        }
                    });
                    futureList.add(future);
                }
            }
            isResult(futureList);
            DataMgr.makeExcelData2Txt("");
            DataMgr.outText("活动-"+activityId);
            System.err.println("``````============================================"+activityId+"完成");
        }
        for(int activityId : activityIdList){
            futureList = new ArrayList<>();
            for(Long serverId : serverList){
                if(ServerMgr.getServerInfoList().containsKey(serverId)){
                    ServerInfo serverInfo = ServerMgr.getServerInfoList().get(serverId);
                    Future future = executorService.submit(new Callable<Boolean>() {
                        @Override
                        public Boolean call() throws Exception {
                            GameServer testGameServer = new GameServer(serverInfo);
                            TrystAc touhu = new TrystAc(testGameServer);
                            touhu.goAllActivityAll(activityId);
                            return true;
                        }
                    });
                    futureList.add(future);
                }
            }
            isResult(futureList);
            DataMgr.makeExcelData2Txt("");
            DataMgr.outText("活动参与-"+activityId);
            System.err.println("``````============================================"+activityId+"完成");
        }
        for(int activityId : activityIdList){
            futureList = new ArrayList<>();
            for(Long serverId : serverList){
                if(ServerMgr.getServerInfoList().containsKey(serverId)){
                    ServerInfo serverInfo = ServerMgr.getServerInfoList().get(serverId);
                    Future future = executorService.submit(new Callable<Boolean>() {
                        @Override
                        public Boolean call() throws Exception {
                            GameServer testGameServer = new GameServer(serverInfo);
                            TrystAc touhu = new TrystAc(testGameServer);
                            touhu.goAllActivityPIFU(activityId);
                            return true;
                        }
                    });
                    futureList.add(future);
                }
            }
            isResult(futureList);
            DataMgr.makeExcelData2Txt("");
            DataMgr.outText("皮肤获得情况-"+activityId);
            System.err.println("``````============================================"+activityId+"完成");
        }*/
        for(int activityId : activityIdList){
            futureList = new ArrayList<>();
            for(Long serverId : serverList){
                if(ServerMgr.getServerInfoList().containsKey(serverId)){
                    ServerInfo serverInfo = ServerMgr.getServerInfoList().get(serverId);
                    Future future = executorService.submit(new Callable<Boolean>() {
                        @Override
                        public Boolean call() throws Exception {
                            GameServer testGameServer = new GameServer(serverInfo);
                            TrystAc touhu = new TrystAc(testGameServer);
                            touhu.acUser(activityId);
                            return true;
                        }
                    });
                    futureList.add(future);
                }
            }
            isResult(futureList);
            DataMgr.makeExcelData2Txt("");
            DataMgr.outText("活动期间的活跃玩家-"+activityId);
            System.err.println("``````============================================"+activityId+"完成");
        }
        for(int activityId : activityIdList){
            futureList = new ArrayList<>();
            for(Long serverId : serverList){
                if(ServerMgr.getServerInfoList().containsKey(serverId)){
                    ServerInfo serverInfo = ServerMgr.getServerInfoList().get(serverId);
                    Future future = executorService.submit(new Callable<Boolean>() {
                        @Override
                        public Boolean call() throws Exception {
                            GameServer testGameServer = new GameServer(serverInfo);
                            TrystAc touhu = new TrystAc(testGameServer);
                            touhu.acJoin(activityId);
                            return true;
                        }
                    });
                    futureList.add(future);
                }
            }
            isResult(futureList);
            DataMgr.makeExcelData2Txt("");
            DataMgr.outText("活动参与人数-"+activityId);
            System.err.println("``````============================================"+activityId+"完成");
        }
        for(int activityId : activityIdList){
            futureList = new ArrayList<>();
            for(Long serverId : serverList){
                if(ServerMgr.getServerInfoList().containsKey(serverId)){
                    ServerInfo serverInfo = ServerMgr.getServerInfoList().get(serverId);
                    Future future = executorService.submit(new Callable<Boolean>() {
                        @Override
                        public Boolean call() throws Exception {
                            GameServer testGameServer = new GameServer(serverInfo);
                            TrystAc touhu = new TrystAc(testGameServer);
                            touhu.caishiGet(activityId);
                            return true;
                        }
                    });
                    futureList.add(future);
                }
            }
            isResult(futureList);
            DataMgr.makeExcelData2Txt("");
            DataMgr.outText("采诗官获得情况-"+activityId);
            System.err.println("``````============================================"+activityId+"完成");
        }
    }
}
